package com.mysoft.gfyx.clue.controller;

import com.alibaba.fastjson.JSON;
import com.mysoft.framework.modeling.dto.ListDataResult;
import com.mysoft.framework.modeling.dto.LoadDataParams;
import com.mysoft.framework.mvc.api.Controller;
import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.clue.controller.dto.MySubscriptionPageDto;
import com.mysoft.gfyx.clue.controller.dto.MySubscriptionReqDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.AddRadarSubscriptionRequestDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.AddSubscriptionRequestDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.GetSubscriptionConfigRequestDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.GetWxQrCodeRequestDto;
import com.mysoft.gfyx.clue.service.SubscriptionService;
import com.mysoft.gfyx.clue.service.dto.QrCodeDataDto;
import com.mysoft.gfyx.common.util.LogUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

@PubService(value = "/subscriptionPub", prefix = RequestPrefix.PUB)
public class SubscriptionPubController extends Controller {
    @Autowired
    private LogUtil logUtil;

    @Resource
    private SubscriptionService subscriptionService;

    @PubAction(value = "/getLatestOpportunities", method = RequestMethod.POST)
    public MySubscriptionPageDto getLatestOpportunities(@RequestBody MySubscriptionReqDto reqDto) {
        return subscriptionService.getLatestOpportunitiesList(reqDto.getPage(), reqDto.getPageSize());
    }

    @PubAction(value = "/isSetSubscriptionConfig", method = RequestMethod.POST)
    public boolean isSetSubscriptionConfig() {
        return subscriptionService.isSetSubscriptionConfig();
    }

    @PubAction(value = "/isSetAdminSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/isSetAdminSubscription", notes = "保存bu的区域权限，并且将权限给到一批用户")
    public Object isSetAdminSubscription() {
        return subscriptionService.isSetAdminSubscription();
    }

    @PubAction(value = "/applyCron", method = RequestMethod.POST)
    @ApiOperation(value = "/applyCron", notes = "应用当前配置到调度，后期调度进入开户平台则不再使用")
    public boolean applyCron() {
        return subscriptionService.applyCron();
    }

    @PubAction(value = "/getSubscriptionConfig", method = RequestMethod.POST)
    @ApiOperation(value = "/getSubscriptionConfig", notes = "获取当前用户的订阅配置")
    public Object getSubscriptionConfig(@RequestBody GetSubscriptionConfigRequestDto getSubscriptionConfigRequestDto) {
        return subscriptionService.getMySubscription(getSubscriptionConfigRequestDto.getType());
    }

    @PubAction(value = "/mySubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/mySubscription", notes = "商机订阅列表")
    public ListDataResult mySubscription(@RequestBody LoadDataParams options) {
        return subscriptionService.loadMySubscriptionDataBySql(options);
    }

    @PubAction(value = "/addSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/addSubscription", notes = "添加商机订阅")
    public Boolean addSubscription(@RequestBody AddSubscriptionRequestDto dto) {
        return subscriptionService.addSubscription(dto);
    }

    @PubAction(value = "/addRadarSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/addRadarSubscription", notes = "添加线索订阅")
    public Boolean addRadarSubscription(@RequestBody AddRadarSubscriptionRequestDto dto) {
        return subscriptionService.addRadarSubscription(dto);
    }

    @PubAction(value = "/getWxQrCode", method = RequestMethod.POST)
    @ApiOperation(value = "/getWxQrCode", notes = "获取公众号二维码")
    public QrCodeDataDto getWxQrCode() {
        return subscriptionService.getWxQrCode();
    }

    @PubAction(value = "/getBindStatus", method = RequestMethod.POST)
    @ApiOperation(value = "/getBindStatus", notes = "获取公众号关注状态")
    public QrCodeDataDto getBindStatus(@RequestBody GetWxQrCodeRequestDto getWxQrCodeRequestDto) {
        return subscriptionService.getBindStatus(getWxQrCodeRequestDto);
    }
}
